{% extends 'base.twig' %}
{% block style %}
    <style>
        .table thead tr th{
            height:30px; line-height: 30px; text-align: center;}
        .table tbody tr td{
            height:30px; line-height: 30px; text-align: center;}
        </style>
        <link href="template/plugins/pnotify/css/pnotify.custom.css" rel="stylesheet" type="text/css">
        <script src="template/plugins/pnotify/js/pnotify.custom.js" type="text/javascript"></script>
    {% endblock %}
    {% block content %}
        <section id="main-content">
        <section class="wrapper">
            <div class="row mt">
                <div class="col-lg-12">
                    <div class="content-panel">
                        <h4><i class="fa fa-directory"></i> 文章列表  <a class="btn btn-success pull-right" href="article.php?act=edit"> 增加文章 </a></h4>
                        <section class="filter bg-warning" style="padding: 10px 0;">
                            <form action="article.php" method="GET">
                                <div class="row">
                                    <div class="col-sm-3">
                                        <div class="input-group">
                                            <span class="input-group-addon">域名</span>
                                            <input type="text" class="form-control" name="domain" value="{{ domain }}">
                                        </div>
                                    </div>
                                    <button type="submit" class="btn btn-default"><i class="fa fa-search"></i> 搜索 </button>
                                </div>
                            </form>
                        </section>
                        <section id="unseen">
                            <table class="table table-bordered ">
                                <thead>
                                    <tr>
                                        <th>域名</th>
                                        <th>排序</th>
                                        <th>id</th>
                                        <th>标题</th>
                                        <th>添加时间</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {% for g in goodsList %}
                                        <tr class="{% if g.is_del==1 %}bg-danger{% endif %}">
                                            <td>{{ g.domain }}</td>
                                            <td><input type="text" size="2" value="{{ g.sort }}" article_id[]="{{ g.article_id }}" name="sort[]"></td>
                                            <td>{{ g.article_id }}</td>
                                            <td>{{ g.title }}</td>
                                            <td>{{ g.add_time }}</td>
                                            <td>
                                                {% if g.is_del ==1 %}
                                                    <a class="btn btn-success" onclick="delproduct({{ g.article_id }}, 0);"><i class="fa fa-edit"></i> 恢复 </a>
                                                {% else %}
                                                    <a class="btn btn-primary" href="article.php?article_id={{ g.article_id }}&act=edit"><i class="fa fa-edit"></i> 编辑</a>
                                                    <a class="btn btn-danger"  onclick="delproduct({{ g.article_id }}, 1);"><i class="fa fa-edit"></i> 删除 </a>
                                                {% endif %}
                                            </td>
                                        </tr>
                                    {% endfor %}
                                </tbody>
                            </table>
                            <div class="text-left">
                                <button class="btn btn-success sort">更新排序</button>
                            </div>
                            <div class="text-center">
                                {{ pageHtml|raw }}
                            </div>
                        </section>
                    </div>
                </div>
            </div>
        </section>
    </section>
    <script type="text/javascript">
        highlight_subnav('article.php?');
        function delproduct(product_id, is_del) {

        var url = 'article.php?';
        var json = {article_id:product_id, is_del:is_del, act:"del"};
        $.ajax({
        url : url,
                data : json,
                type : "post",
                dataType:"json",
                success : function(data) {
                if (data.ret)
                {
                location.reload()
                }
                else{
                new PNotify({
                title: '错误！！',
                        text: data.msg,
                        type: 'error',
                        addclass: 'stack-bar-top'
                });
                }

                },
                error:function(XMLHttpRequest, textStatus, errorThrown){
                alert(errorThrown);
                }

        });
        }
        $(".sort").click(function () {

        var article_id = [];
        var sort = [];
        var $this = $("input[name='sort[]']");
        $this.each(function () {
        article_id.push($(this).attr("article_id[]"))
                sort.push($(this).val())
        })

                $.post('article.php', {act:"sort", article_id:article_id, sort:sort}).success(function (data) {
        var ret = JSON.parse(data)
                if (ret.ret)
        {
        location.reload();
        }
        })

        })
    </script>
{% endblock %}